package com.foxsteps.gsonformat.model;

import com.foxsteps.gsonformat.tools.ux.CellProvider;
import com.foxsteps.gsonformat.tools.ux.Selector;
import com.intellij.psi.PsiType;

import java.io.Serializable;
import java.util.List;

/**
 * @author dongxuanliang252
 * @date 2018-12-18 15:13
 */

public class FieldBean implements Selector, CellProvider, Serializable {

    private String name;
    private String type;
    private String description;
    private List<FieldBean> childFieldList;
    private boolean ignoreFlag = false;
    private transient boolean checked = true;
    private transient PsiType psiType;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<FieldBean> getChildFieldList() {
        return childFieldList;
    }

    public void setChildFieldList(List<FieldBean> childFieldList) {
        this.childFieldList = childFieldList;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public PsiType getPsiType() {
        return psiType;
    }

    public void setPsiType(PsiType psiType) {
        this.psiType = psiType;
    }

    public boolean isIgnoreFlag() {
        return ignoreFlag;
    }

    public void setIgnoreFlag(boolean ignoreFlag) {
        this.ignoreFlag = ignoreFlag;
    }

    @Override
    public String getCellTitle(int index) {
        if (index == 0) {
            return name;
        } else if (index == 1) {
            return type;
        } else if (index == 2) {
            return description;
        }
        return null;
    }

    @Override
    public void setValueAt(int column, String text) {
        if (column == 0) {
            setName(text);
        } else if (column == 1) {
            setType(text);
        } else if (column == 2) {
            setDescription(text);
        }
    }

    @Override
    public void setSelect(boolean select) {
        setChecked(select);
    }

    @Override
    public boolean getSelect() {
        return isChecked();
    }

}
